<!DOCTYPE html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<title>群组详情</title>
		<link rel="stylesheet" href="../../assets/libs/layui/css/layui.css" />
		<link rel="stylesheet" href="../../assets/css/swiper.min.css" />
		<link rel="stylesheet" href="../../assets/css/admin.css" />
		<link rel="stylesheet" href="../../module/formSelects/formSelects-v4.css" />
		<link rel="stylesheet" href="../../assets/css/simditor.css" />
	</head>

	<body>
		<div class="layui-card">
			<div class="layui-card-header">
				<h2 class="header-title">群组列表</h2>
				<span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>群组列表</cite></a>
        </span>
			</div>
			<div class="layui-card-body">
				<div class="layui-row layui-col-space20">
					<div class="layui-col-xs6 layui-col-md6">
						<div class="layui-form toolbar">
							<!--<label>查询方式</label>
							<div class="layui-input-inline">
								<select name="lxz" id="userSele" lay-verify="required">
									<option value="userId">ID搜索</option>
									<option selected="selected" value="nickname">昵称搜索</option>
									<option value="username">手机号搜索</option>
								</select>
							</div>
							<input id="queryUser" class="layui-input search-input" type="text" placeholder="请输入" />&emsp;
							<button id="logr-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>-->
						</div>
					</div>
					<div class="layui-col-xs2 layui-col-md2 layui-col-md-offset4">
						<div class="layui-btn-group groupTable" style="">
							<button class="layui-btn layui-btn-normal" data-type="getTui" style="float:left;margin-right: 8px!important;">推送消息</button>
							<i class="layui-clear"></i>
						</div>
					</div>
					<div class="layui-clear"></div>
				</div>
				<div class="layui-btn-container">
					<button id="userdesc" class="layui-btn">用户ID<div id="userd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
					<button id="healthdesc" class="layui-btn">健康<div id="healthd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
					<button id="orangedesc" class="layui-btn">脏腑<div id="zfd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
					<button id="spiritdesc" class="layui-btn">精神<div id="jsd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
					<button id="sportdesc" class="layui-btn">运动<div id="ydd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
					<button id="sleepdesc" class="layui-btn">睡眠<div id="smd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
					<button id="qddesc" class="layui-btn">渠道<div id="qdd" class="zbyicon"><i class="layui-icon layui-icon-triangle-d"></i></div></button>
				</div>
				<table class="layui-table" id="gi-table" lay-filter="giList"></table>
			</div>
		</div>

		<script type="text/html" id="giBar">
			<a class="layui-btn layui-btn-primary layui-btn-sm" title="查看详情" lay-event="open"><i class="layui-icon layui-icon-layer"></i></a>
			<a class="layui-btn layui-btn-sm zbys" title="沟通" lay-event="del"><i class="layui-icon layui-icon-dialogue"></i></a>
			<a class="layui-btn layui-btn-danger  layui-btn-sm" title="移除用户" lay-event="edit"><i class="layui-icon layui-icon-delete"></i></a>
		</script>

		<script type="text/javascript" src="../../assets/libs/jquery-3.2.1.min.js"></script>
		<script type="text/javascript" src="../../assets/libs/layui/layui.js"></script>
		<script type="text/javascript" src="../../module/common.js"></script>
		<script type="text/javascript" src="../../assets/libs/q.js"></script>
		<script>
			layui.config({
				base: '../../module/'
			}).extend({
				formSelects: 'formSelects/formSelects-v4',
				treetable: 'treetable-lay/treetable'
			}).use(['config', 'index', 'element'], function() {
				var config = layui.config;
				var index = layui.index;
				var element = layui.element;
				// 检查多标签功能是否开启
				index.checkPageTabs();

			});

			layui.use(['table', 'util', 'config', 'index', 'admin'], function() {
				//		var layddte = layui.layddte;
				var admin = layui.admin;
				var index = layui.index;
				var table = layui.table;
				var config = layui.config;
				var util = layui.util;
				var com = layui.common;
				var index2 = parent.layui.index;
				var admin2 = parent.layui.admin;
				var idRand = 1
				var timeRank = 1
				var allRank = 1
				var sleepRank = 1
				var sportRank = 1
				var spiritRank = 1
				var visceraRank = 1

				var selectGroup = admin.getTempData('groupId');

				var $ = layui.$,
					active = {
						getTui: function() {
							var checkStatus = table.checkStatus('gi-table'),
								data = checkStatus.data;
							admin2.putTempData('selectUser2', data);
							var title = '推送消息';
							admin2.popupCenter({
								title: title,
								path: 'components/system/userMsg.html',
								finish: function() {
								}
							});
						}
					};

				$('.groupTable .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});

				//		$('#groupUsersearch').click(function() {
				//			var searchAccount = $('#queryGroupUser').val().trim();
				//			usergroupListV("u.user_id asc", searchAccount);
				//		})

				$('#userdesc').click(function() {
					if(idRand == 1) {
						idRand = 0;
						$('#userd').addClass("zbyicon2");
						$("#userd").removeClass("zbyicon");
						usergroupListV("u.user_id desc", null);
					} else {
						idRand = 1;
						$('#userd').addClass("zbyicon");
						$("#userd").removeClass("zbyicon2");
						usergroupListV("u.user_id asc", null);
					}
					closeOther(1, timeRank, allRank, sleepRank, sportRank, spiritRank, visceraRank);
				})

				$('#healthdesc').click(function() {
					if(allRank == 1) {
						allRank = 0;
						recordstate = "so.score_all desc";
						$('#healthd').addClass("zbyicon2");
						$("#healthd").removeClass("zbyicon");
						usergroupListV("so.score_all desc", null);
					} else {
						allRank = 1;
						recordstate = "sh.score_all asc";
						$('#healthd').addClass("zbyicon");
						$("#healthd").removeClass("zbyicon2");
						usergroupListV("so.score_all asc", null);
					}
					closeOther(idRand, timeRank, 1, sleepRank, sportRank, spiritRank, visceraRank);
				})

				$('#orangedesc').click(function() {
					if(visceraRank == 1) {
						visceraRank = 0;
						recordstate = "so.time_viscera desc";
						$('#zfd').addClass("zbyicon2");
						$("#zfd").removeClass("zbyicon");
						usergroupListV("so.time_viscera desc", null);
					} else {
						visceraRank = 1;
						recordstate = "so.time_viscera asc";
						$('#zfd').addClass("zbyicon");
						$("#zfd").removeClass("zbyicon2");
						usergroupListV("so.time_viscera asc", null);
					}
					closeOther(idRand, timeRank, allRank, sleepRank, sportRank, spiritRank, 1);
				})

				$('#sleepdesc').click(function() {
					if(sleepRank == 1) {
						sleepRank = 0;
						recordstate = "so.time_sleep desc";
						$('#smd').addClass("zbyicon2");
						$("#smd").removeClass("zbyicon");
						usergroupListV("so.time_sleep desc", null);
					} else {
						sleepRank = 1;
						recordstate = "so.time_sleep asc";
						$('#smd').addClass("zbyicon");
						$("#smd").removeClass("zbyicon2");
						usergroupListV("so.time_sleep asc", null);
					}
					closeOther(idRand, timeRank, allRank, 1, sportRank, spiritRank, visceraRank);
				})

				$('#spiritdesc').click(function() {
					if(spiritRank == 1) {
						spiritRank = 0;
						recordstate = "so.time_sprite desc";
						$('#jsd').addClass("zbyicon2");
						$("#jsd").removeClass("zbyicon");
						usergroupListV("so.time_sprite desc", null);
					} else {
						spiritRank = 1;
						recordstate = "so.time_sprite asc";
						$('#jsd').addClass("zbyicon");
						$("#jsd").removeClass("zbyicon2");
						usergroupListV("so.time_sprite asc", null);
					}
					closeOther(idRand, timeRank, allRank, sleepRank, sportRank, 1, visceraRank);
				})

				$('#sportdesc').click(function() {
					if(sportRank == 1) {
						sportRank = 0;
						recordstate = "so.time_sport desc";
						$('#ydd').addClass("zbyicon2");
						$("#ydd").removeClass("zbyicon");
						usergroupListV("so.time_sport desc", null);
					} else {
						sportRank = 1;
						recordstate = "so.time_sport asc";
						$('#ydd').addClass("zbyicon");
						$("#ydd").removeClass("zbyicon2");
						usergroupListV("so.time_sport asc", null);
					}
					closeOther(idRand, timeRank, allRank, sleepRank, 1, spiritRank, visceraRank);
				})

				$('#qddesc').click(function() {
					if(timeRank == 1) {
						timeRank = 0;
						recordstate = "u.org_id desc";
						$('#qdd').addClass("zbyicon2");
						$("#qdd").removeClass("zbyicon");

						usergroupListV("u.org_id desc", null);
					} else {
						timeRank = 1;
						recordstate = "u.org_id asc";
						$('#qdd').addClass("zbyicon");
						$("#qdd").removeClass("zbyicon2");
						usergroupListV("u.org_id asc", null);
					}
					closeOther(idRand, 1, allRank, sleepRank, sportRank, spiritRank, visceraRank);
				})

				function closeOther(idRands, timeRanks, allRanks, sleepRanks, sportRanks, spiritRanks, visceraRanks) {

					if(idRands == 0) {
						idRand = 1;
						$('#userd').addClass("zbyicon");
						$("#userd").removeClass("zbyicon2");
					}
					if(timeRanks == 0) {
						timeRank = 1;
						$('#qdd').addClass("zbyicon");
						$("#qdd").removeClass("zbyicon2");
					}
					if(allRanks == 0) {
						allRank = 1;
						$('#healthd').addClass("zbyicon");
						$("#healthd").removeClass("zbyicon2");
					}
					if(sleepRanks == 0) {
						sleepRank = 1;
						$('#smd').addClass("zbyicon");
						$("#smd").removeClass("zbyicon2");
					}
					if(sportRanks == 0) {
						sportRank = 1;
						$('#ydd').addClass("zbyicon");
						$("#ydd").removeClass("zbyicon2");
					}
					if(spiritRanks == 0) {
						spiritRank = 1;
						$('#jsd').addClass("zbyicon");
						$("#jsd").removeClass("zbyicon2");
					}
					if(visceraRanks == 0) {
						visceraRank = 1;
						$('#zfd').addClass("zbyicon");
						$("#zfd").removeClass("zbyicon2");
					}
				}

				showUIs()

				function showUIs() {

					var alog = config.getTempData('loginInfo');
					$.ajax({
						type: "POST",
						url: infosUser,
						data: {
							userId: alog.userId
						},
						dataType: "json",
						xhrFields: {
							withCredentials: true
						},
						success: function(data) {
							console.log(data.rows)
							admin.putTempData('yigeids', data);
							usergroupListV('u.user_id asc', null)
						},
						error: function(result) {
							console.log(result);
						},
					});
				}

				function showGiTable(tabledata) {
					table.render({
						elem: '#gi-table',
						id: 'gi-table',
						data: tabledata,
						page: true,
						limit: 50,
						response: {
							countName: 'data.total' //数据总数的字段名称，默认：count
						},
						cols: [
							[{
									checkbox: true
								}, {
									field: 'headPortrait',
									title: '用户头像',
									style: 'height:70px;padding:0;',
									templet: function(b) {
										if(b.headPortrait == null || b.headPortrait == "") {
											var s = '<div><img src="../../assets/images/mrtx.png" width="50px"  height="50px" /></div>'
											return s
										} else {
											var s = '<div><img src="'
											s += b.headPortrait;
											s += '" width="50px"  height="50px" /></div>'
											return s
										}
									}
								},
								{
									field: 'userId',
									title: '用户ID'
								},
								{
									field: 'nickname',
									title: '用户昵称',
									templet: function(b) {
										if(b.nickname != null) {
											if(b.nickname.length == 1) {
												return b.nickname
											} else if(b.nickname.length == 2) {
												var a = b.nickname;
												a = a.substring(0, 1)
												return a + "*"
											} else {
												if(b.nickname != null) {
													var a = b.nickname;
													var x = a.substring(0, 1)
													var c = a.substring(b.nickname.length - 1, b.nickname.length)
													return x + "***" + c
												}
											}
										} else {
											return "未填写"
										}
									}
								},
								{
									field: 'sex',
									title: '性别'
								},
								{
									field: 'birthday',
									title: '年龄',
									templet: function(b) {
										return birthday(b.birthday) + "岁";
									}
								},
								{
									field: 'scoreSprite',
									title: '健康数据',
									width: 175,
									templet: function(b) {
										var a0, a1, a2, a3, a4, a5;
										if(b.continueAll) {
											a0 = b.continueAll
										} else {
											a0 = ""
										}

										if(b.scoreSprite) {
											a1 = b.scoreSprite
										} else {
											a1 = ""
										}

										if(b.scoreViscera) {
											a2 = b.scoreViscera
										} else {
											a2 = ""
										}

										if(b.scoreSleep) {
											a3 = b.scoreSleep
										} else {
											a3 = ""
										}

										if(b.scoreSport) {
											a4 = b.scoreSport
										} else {
											a4 = ""
										}

										if(b.scoreAll) {
											a5 = b.scoreAll
										} else {
											a5 = ""
										}

										var a = "<table><tr>" +
											"<td> " + healthNums(b.scoreAll) + "</td>" +
											"<td>" + userSirit(b.scoreSprite) + "</td>" +
											"<td>" + userOrgan(b.scoreViscera) + "</td>" +
											"<td>" + userSleep(b.scoreSleep) + "</td>" +
											"<td>" + userSport(b.scoreSport) + "</td>" +
											"<td> " + jianc(b.continueAll) + "</td>" +
											"<tr/>" +
											"<tr style='text-align: center;'>" +
											"<td>" + a5 + "</td>" +
											"<td>" + a1 + "</td>" +
											"<td>" + a2 + "</td>" +
											"<td>" + a3 + "</td>" +
											"<td>" + a4 + "</td>" +
											"<td> " + a0 + "</td>" +
											"<tr/>" +
											"</table>"
										return a
										//								return +userSirit(b.scoreSprite) + userOrgan(b.scoreViscera) + userSleep(b.scoreSleep) + userSport(b.scoreSport) + '<br/>' +
										//									a0 + a1 + a2 + a3 + a4
									}
								},
								{
									field: 'orgName',
									title: '渠道',
									templet: function(d) {
										if(d.orgName == null) {
											return "松果健康";
										} else {
											return d.orgName
										}
									}
								},
								{
									field: 'addTime',
									templet: function(d) {
										return d.addTime.substring(0, 10, '');
									},
									title: '创建时间'
								}, {
									field: 'caozuo',
									title: '操作',
									toolbar: "#giBar"
								}
							]
						]
					});
					var kid = admin.getTempData("yigeids")
					if(kid.rows.customerServiceId == null) {
						$('.zbys').css("display", "none");
					}
				}

				function usergroupListV(desca, quer) {
					layer.load(2);
					$.ajax({
						type: "POST",
						url: groupUser,
						data: {
							params: JSON.stringify({
								sortOrder: desca,
								pageSize: 1000,
								pageNumber: 1,
								groupId: selectGroup.groupId,
								search: quer
							})
						},
						dataType: "json",
						xhrFields: {
							withCredentials: true
						},
						beforeSend: function(request) {},
						success: function(data) {
							layer.closeAll('loading');
							showGiTable(data.rows);

						},
						error: function(result) {
							console.log(result);
							config.removeToken();
							location.replace('../../login.html');
						},
					});
				}

				function birthday(strBirthday) {
					if(strBirthday != null) {

						var returnAge;
						var strBirthdayArr = strBirthday.split("-");
						var birthYear = strBirthdayArr[0];
						var birthMonth = strBirthdayArr[1];
						var birthDay = strBirthdayArr[2];

						d = new Date();
						var nowYear = d.getFullYear();
						var nowMonth = d.getMonth() + 1;
						var nowDay = d.getDate();

						if(nowYear == birthYear) {
							returnAge = 0; //同年 则为0岁
						} else {
							var ageDiff = nowYear - birthYear; //年之差
							if(ageDiff > 0) {
								if(nowMonth == birthMonth) {
									var dayDiff = nowDay - birthDay; //日之差
									if(dayDiff < 0) {
										returnAge = ageDiff - 1;
									} else {
										returnAge = ageDiff;
									}
								} else {
									var monthDiff = nowMonth - birthMonth; //月之差
									if(monthDiff < 0) {
										returnAge = ageDiff - 1;
									} else {
										returnAge = ageDiff;
									}
								}
							} else {
								returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
							}
						}

						return returnAge; //返回周岁年龄

					}
				}

				function healthNums(nums) {
					if(nums != null) {
						return '<img class="userScore" title="健康分值：' + nums + '" src="../../assets/images/jingshen_songguo1@2x.png" />'
					} else {
						return ''
					}
				}

				function jianc(nums) {
					if(nums != null) {
						return '<img class="userScore" title="持续天数：' + nums + '" src="../../assets/images/calendar.png" />'
					} else {
						return ''
					}
				}

				function userSleep(sleep) {
					if(sleep != null) {
						return '<img class="userScore" title="睡眠分值：' + sleep + '" src="../../assets/images/u555.png" />'
					} else {
						return ''
					}
				}

				function userOrgan(organ) {
					if(organ != null) {
						return '<img class="userScore" title="脏腑分值：' + organ + '" src="../../assets/images/u552.png" />'
					} else {
						return ''
					}
				}

				function userSport(sport) {
					if(sport != null) {
						return '<img class="userScore" title="运动分值：' + sport + '" src="../../assets/images/u553.png" />'
					} else {
						return ''
					}
				}

				function userSirit(sirit) {
					if(sirit != null) {
						return '<img class="userScore" title="精神分值：' + sirit + ' " src="../../assets/images/u551.png" />'
					} else {
						return ''
					}
				}

				table.on('tool(giList)', function(obj) {
					var data = obj.data;
					if(obj.event === 'edit') {
						layer.confirm('确定将此用户移出群组吗？', function(i) {
							layer.close(i);
							layer.load(2);
							$.ajax({
								type: "POST",
								url: delUserMamber,
								data: {
									groupInfoId: data.groupInfoId
								},
								dataType: "json",
								xhrFields: {
									withCredentials: true
								},
								success: function(data) {
									layer.closeAll('loading');
									if(data.code == 0) {
										layer.msg(data.msg, {
											icon: 1
										});
										usergroupListV();
									} else {
										layer.msg(data.msg, {
											icon: 2
										});
									}
								},
								error: function(result) {
									console.log(result);
								}
							});
						});

					} else if(obj.event === 'open') {
						admin.putTempData(data.sungoId + "u", data); // 用缓存传递参数

						if(data.nickname != null) {
							if(data.nickname.length == 1) {} else if(data.nickname.length == 2) {
								var a = data.nickname;
								a = a.substring(0, 1)
								data.nickname = a + "*"
							} else {
								if(data.nickname != null) {
									var a = data.nickname;
									var x = a.substring(0, 1)
									var c = a.substring(data.nickname.length - 1, data.nickname.length)
									data.nickname = x + "***" + c
								}
							}
						} else {
							data.nickname = "未填写"
						}

						// 不分离版本用后台地址
						index2.openNewTab({
							title: data.nickname,
							url: 'components/system/userinfo.html',
							menuId: data.sungoId + "u"
						});
					} else if(obj.event === 'del') {
						var kid = admin.getTempData("yigeids")
						if(kid.rows.customerServiceId == data.customerServiceId) {
							admin2.liaotian(data.userId, data.nickname)
						} else {
							layer.alert("您不是此用户的客服人员，请您在用户列表设置！")
						}
					}
				});

			});
		</script>
	</body>

</html>